package Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Bean.Score;
import Dao.ScoreDao;

public class ShowAllScoreServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		ArrayList scoreList = new ArrayList();
		ScoreDao scoreDao = new ScoreDao();
		ServletContext application=this.getServletContext();
		try {
			scoreList = scoreDao.queryAllScore();
			request.setAttribute("scoreList", scoreList);
			application.getRequestDispatcher("/showAllScore.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String sid = request.getParameter("sid");
		String cid = request.getParameter("cid");
		Score score = new Score();
		ScoreDao scoreDao = new ScoreDao();
		ServletContext application=this.getServletContext();
		try {
			score = scoreDao.queryScoreBySidCid(sid, cid);
			ArrayList scoreList = new ArrayList();
			scoreList.add(score);
			request.setAttribute("scoreList", scoreList);
			application.getRequestDispatcher("/showAllScore.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
